from typing import Dict, Optional
from .logger import logger

# 主题样式表定义
THEMES = {
    'light': """
        QMainWindow {
            background-color: #f0f0f0;
        }
        QWidget {
            color: #333333;
            font-size: 12px;
        }
        QPushButton {
            background-color: #ffffff;
            border: 1px solid #cccccc;
            border-radius: 4px;
            padding: 5px 15px;
            min-width: 80px;
        }
        QPushButton:hover {
            background-color: #e6e6e6;
            border-color: #adadad;
        }
        QPushButton:pressed {
            background-color: #d4d4d4;
            border-color: #8c8c8c;
        }
        QPushButton:disabled {
            background-color: #f5f5f5;
            border-color: #dddddd;
            color: #999999;
        }
        QTableWidget {
            background-color: #ffffff;
            border: 1px solid #dddddd;
            gridline-color: #dddddd;
        }
        QTableWidget::item {
            padding: 5px;
        }
        QTableWidget::item:selected {
            background-color: #e6e6e6;
        }
        QHeaderView::section {
            background-color: #f5f5f5;
            padding: 5px;
            border: 1px solid #dddddd;
            border-left: 0px;
            border-top: 0px;
        }
        QCheckBox {
            spacing: 5px;
        }
        QCheckBox::indicator {
            width: 15px;
            height: 15px;
        }
        QLabel {
            color: #333333;
        }
        QStatusBar {
            background-color: #f5f5f5;
            color: #666666;
        }
        QMenuBar {
            background-color: #f5f5f5;
            border-bottom: 1px solid #dddddd;
        }
        QMenuBar::item {
            padding: 5px 10px;
        }
        QMenuBar::item:selected {
            background-color: #e6e6e6;
        }
        QMenu {
            background-color: #ffffff;
            border: 1px solid #cccccc;
        }
        QMenu::item {
            padding: 5px 20px;
        }
        QMenu::item:selected {
            background-color: #e6e6e6;
        }
    """,
    
    'dark': """
        QMainWindow {
            background-color: #2b2b2b;
        }
        QWidget {
            color: #f0f0f0;
            font-size: 12px;
        }
        QPushButton {
            background-color: #3b3b3b;
            border: 1px solid #505050;
            border-radius: 4px;
            padding: 5px 15px;
            min-width: 80px;
            color: #f0f0f0;
        }
        QPushButton:hover {
            background-color: #454545;
            border-color: #666666;
        }
        QPushButton:pressed {
            background-color: #505050;
            border-color: #777777;
        }
        QPushButton:disabled {
            background-color: #2b2b2b;
            border-color: #3b3b3b;
            color: #666666;
        }
        QTableWidget {
            background-color: #2b2b2b;
            border: 1px solid #3b3b3b;
            gridline-color: #3b3b3b;
            color: #f0f0f0;
        }
        QTableWidget::item {
            padding: 5px;
        }
        QTableWidget::item:selected {
            background-color: #454545;
        }
        QHeaderView::section {
            background-color: #3b3b3b;
            padding: 5px;
            border: 1px solid #505050;
            border-left: 0px;
            border-top: 0px;
            color: #f0f0f0;
        }
        QCheckBox {
            spacing: 5px;
            color: #f0f0f0;
        }
        QCheckBox::indicator {
            width: 15px;
            height: 15px;
        }
        QLabel {
            color: #f0f0f0;
        }
        QStatusBar {
            background-color: #3b3b3b;
            color: #b0b0b0;
        }
        QMenuBar {
            background-color: #3b3b3b;
            border-bottom: 1px solid #505050;
            color: #f0f0f0;
        }
        QMenuBar::item {
            padding: 5px 10px;
        }
        QMenuBar::item:selected {
            background-color: #454545;
        }
        QMenu {
            background-color: #2b2b2b;
            border: 1px solid #505050;
            color: #f0f0f0;
        }
        QMenu::item {
            padding: 5px 20px;
        }
        QMenu::item:selected {
            background-color: #454545;
        }
    """
}

def get_theme(theme_name: str) -> Optional[str]:
    """获取主题样式表"""
    try:
        if theme_name not in THEMES:
            logger.warning(f"未找到主题: {theme_name}，使用默认主题")
            theme_name = 'light'
        
        return THEMES[theme_name]
        
    except Exception as e:
        logger.error(f"获取主题失败: {str(e)}")
        return THEMES['light']

def get_available_themes() -> Dict[str, str]:
    """获取所有可用主题"""
    return {
        'light': '浅色主题',
        'dark': '深色主题'
    }
